<template>
  <el-dialog :append-to-body="true" :visible.sync="dialog" title="修改佣金" width="600px">
    <el-form ref="form" :model="form" :rules="rules" size="small" label-width="150px">
      <el-form-item label="佣金金额:" prop="distribution_total">
        <el-input v-model="form.teamCommission" disabled/>
      </el-form-item>
      <el-form-item label="预估佣金：" prop="distribution_total">
        <div>推广员佣金<el-input v-model="form.distribution_total" style="width: 30%" placeholder="请输入"/></div>
        <div style="color: #99a9bf">自动计算，支持手动修改，佣金=佣金总金额 * 佣金比例；</div>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button size="small" @click="cancel">取消</el-button>
      <el-button :loading="addLoading" type="primary" size="small" @click="doSubmit">确认</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { updateCommodityDistributorInfo } from '@/api/mall/cardCommodityList'
export default {
  components: { },
  data() {
    return {
      dialog: false,
      addLoading: false,
      form: {
        team_commodity_list: [],
        distribution_total: 0, // 分销员佣金
        teamCommission: 0 // 团长佣金
      },
      labelList: [], // 公司标签数据，数据源
      selectList: [], // 选中数据的集合
      commodityLabels: [], // 传递过来的商品的标签
      rules: {
      }
    }
  },
  created() {
  },
  methods: {
    cancel() {
      this.resetForm()
    },
    doSubmit() {
      // const reg = /^\+?[1-9][0-9]*$/
      const reg = /^\d+(\.\d+)?$/
      if (!reg.test(this.form.distribution_total)) {
        this.$notify({
          title: '输入内容必须为数字',
          type: 'warning',
          duration: 2500
        })
        return
      }
      // 设置的分销员佣金大于团长佣金，不能进行保存
      if (this.form.teamCommission < this.form.distribution_total) {
        this.$notify({
          title: '分销员佣金不得大于团长佣金',
          type: 'warning',
          duration: 2500
        })
        return
      }
      this.addLoading = true
      updateCommodityDistributorInfo(this.form).then(res => {
        this.addLoading = false
        if (res) {
          this.$notify({
            title: '更新成功',
            type: 'success',
            duration: 2500
          })
          this.resetForm()
          // 刷新页面
          this.$parent.init()
        } else {
          this.$notify({
            title: '更新失败',
            type: 'error',
            duration: 2500
          })
        }
      })
    },
    resetForm() {
      this.dialog = false
      this.$refs['form'].resetFields()
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
  /deep/ .el-input-number .el-input__inner {
    text-align: left;
  }

</style>
